<?php 
namespace town\model;

use town\dmod\DB;
use town\dmod\Model;


/**
 * 分类信息
 */
class Category extends Model
{
	public $tableName = 'categorys';


	/**
	 * 获取分类的字典
	 */
	public function dict()
	{
		static $dict = [];
		if (count($dict)) {
			return $dict;
		}
		$datas = DB::table('categorys')->get();
		foreach ($datas as $key => $value) {
			$dict[$value['id']] = $value['name'];
		};
		return $dict;
	}


	/**
	 * 通过postId 获取分类列表
	 */
	public function cateByPostId($id)
	{
		$data = $this->dict();
		return $data[$id];
	}
}